home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-11-17 | 5.8 KB | 193 lines | [TEXT/MPS ] |
- {
- File: Threads.p
-
- Contains: External Interface to Thread Manager
-
- Copyright: © 1991-1994 by Apple Computer, Inc., all rights reserved.
-
- }
-
- {$IFC UNDEFINED UsingIncludes}
- {$SETC UsingIncludes := 0}
- {$ENDC}
-
- {$IFC NOT UsingIncludes}
- UNIT Threads;
- INTERFACE
- {$ENDC}
-
- {$IFC UNDEFINED UsingThreads}
- {$SETC UsingThreads := 1}
-
- {$I+}
- {$SETC ThreadsIncludes := UsingIncludes}
- {$SETC UsingIncludes := 1}
- {$IFC UNDEFINED UsingTypes}
- {$I $$Shell(PInterfaces)Types.p}
- {$ENDC}
- {$IFC UNDEFINED UsingMemory}
- {$I $$Shell(PInterfaces)Memory.p}
- {$ENDC}
- {$SETC UsingIncludes := ThreadsIncludes}
-
- {$ENDC} { UsingThreads }
-
- { Thread Gestalt Selectors }
- CONST
- gestaltThreadMgrAttr = 'thds'; { Thread Manager attributes }
- gestaltThreadMgrPresent = 0; { bit true if Thread Mgr is present }
- gestaltSpecificMatchSupport = 1; { bit true if Thread Mgr supports exact match creation option }
- gestaltThreadsLibraryPresent = 2; { bit true if ThreadsLibrary (Native version) has been loaded }
-
-
- { Thread states }
- TYPE
- ThreadState = INTEGER;
-
- CONST
- kReadyThreadState = 0;
- kStoppedThreadState = 1;
- kRunningThreadState = 2;
-
- { Thread environment characteristics }
- TYPE
- ThreadTaskRef = Ptr;
-
- { Thread characteristics }
- TYPE
- ThreadStyle = LONGINT;
-
- CONST
- kCooperativeThread = 1;
- kPreemptiveThread = 2;
-
- { Thread identifiers }
- TYPE
- ThreadID = LONGINT;
-
- CONST
- kNoThreadID = 0;
- kCurrentThreadID = 1;
- kApplicationThreadID = 2;
-
- { Options when creating a thread }
- TYPE
- ThreadOptions = LONGINT;
-
- CONST
- kNewSuspend = 1;
- kUsePremadeThread = 2;
- kCreateIfNeeded = 4;
- kFPUNotNeeded = 8;
- kExactMatchThread = 16;
-
- { Information supplied to the custom scheduler }
- TYPE
- SchedulerInfoRecPtr = ^SchedulerInfoRec;
- SchedulerInfoRec = RECORD
- InfoRecSize: LONGINT;
- CurrentThreadID: ThreadID;
- SuggestedThreadID: ThreadID;
- InterruptedCoopThreadID: ThreadID;
- END;
-
- { Routine proc prototypes }
- TYPE
- { Prototype for a thread's entry routine }
- ThreadEntryProcPtr = ProcPtr; { FUNCTION ThreadMain(threadParam: LONGINT): LONGINT; }
-
- { Prototype for a custom scheduler }
- ThreadSchedulerProcPtr = ProcPtr; { FUNCTION ThreadScheduler(schedulerInfo: SchedulerInfoRec): ThreadID; }
-
- { Prototype for a custom switcher }
- ThreadSwitchProcPtr = ProcPtr; { PROCEDURE ThreadSwitcher(threadBeingSwitched: ThreadID; switchProcParam: LONGINT); }
-
- { Prototype for a custom termination notification routine}
- ThreadTerminationProcPtr = ProcPtr; { PROCEDURE ThreadTerminator(threadTerminated: ThreadID; terminationProcParam: LONGINT); }
-
- { Prototypes for debugger new, dispose & schedule thread notification }
- DebuggerNewThreadProcPtr = ProcPtr; { PROCEDURE DebuggerNewThread(threadCreated: ThreadID); }
- DebuggerDisposeThreadProcPtr = ProcPtr; { PROCEDURE DebuggerDisposeThread(threadCreated: ThreadID); }
- DebuggerThreadSchedulerProcPtr = ProcPtr; { FUNCTION DebuggerThreadScheduler(schedulerInfo: SchedulerInfoRec): ThreadID; }
-
-
- { Errors }
- CONST
- threadTooManyReqsErr = -617;
- threadNotFoundErr = -618;
- threadProtocolErr = -619;
-
-
- { Thread Manager routines }
- FUNCTION CreateThreadPool(threadStyle: ThreadStyle; numToCreate: INTEGER; stackSize: Size):OSErr;
- INLINE $303C,$0501,$ABF2;
-
- FUNCTION GetFreeThreadCount(threadStyle: ThreadStyle; VAR freeCount: INTEGER):OSErr;
- INLINE $303C,$0402,$ABF2;
-
- FUNCTION GetSpecificFreeThreadCount ( threadStyle: ThreadStyle; stackSize: Size; VAR freeCount: INTEGER):OSErr;
- INLINE $303C,$0615,$ABF2;
-
- FUNCTION GetDefaultThreadStackSize(threadStyle: ThreadStyle; VAR stackSize: Size):OSErr;
- INLINE $303C,$0413,$ABF2;
-
- FUNCTION ThreadCurrentStackSpace(thread: ThreadID; VAR freeStack: LONGINT):OSErr;
- INLINE $303C,$0414,$ABF2;
-
- FUNCTION NewThread(threadStyle: ThreadStyle; threadEntry: ThreadEntryProcPtr; threadParam: LONGINT; stackSize: Size; options: ThreadOptions; threadResult: LongIntPtr; VAR threadMade: ThreadID):OSErr;
- INLINE $303C,$0E03,$ABF2;
-
- FUNCTION DisposeThread(threadToDump: ThreadID; threadResult: LONGINT; recycleThread: BOOLEAN):OSErr;
- INLINE $303C,$0504,$ABF2;
-
- FUNCTION YieldToThread(suggestedThread: ThreadID):OSErr;
- INLINE $303C,$0205,$ABF2;
-
- FUNCTION YieldToAnyThread:OSErr;
- INLINE $42A7,$303C,$0205,$ABF2;
-
- FUNCTION GetCurrentThread(VAR currentThreadID: ThreadID):OSErr;
- INLINE $303C,$0206,$ABF2;
-
- FUNCTION GetThreadState(threadToGet: ThreadID; VAR threadState: ThreadState):OSErr;
- INLINE $303C,$0407,$ABF2;
-
- FUNCTION SetThreadState(threadToSet: ThreadID; newState: ThreadState; suggestedThread: ThreadID):OSErr;
- INLINE $303C,$0508,$ABF2;
-
- FUNCTION SetThreadStateEndCritical(threadToSet: ThreadID; newState: ThreadState; suggestedThread: ThreadID):OSErr;
- INLINE $303C,$0512,$ABF2;
-
- FUNCTION SetThreadScheduler(threadScheduler: ThreadSchedulerProcPtr):OSErr;
- INLINE $303C,$0209,$ABF2;
-
- FUNCTION SetThreadSwitcher(thread: ThreadID; threadSwitcher: ThreadSwitchProcPtr; switchProcParam: LONGINT; inOrOut: BOOLEAN):OSErr;
- INLINE $303C,$070A,$ABF2;
-
- FUNCTION SetThreadTerminator(thread: ThreadID; threadTerminator: ThreadTerminationProcPtr; terminationProcParam: LONGINT):OSErr;
- INLINE $303C,$0611,$ABF2;
-
- FUNCTION ThreadBeginCritical:OSErr;
- INLINE $303C,$000B,$ABF2;
-
- FUNCTION ThreadEndCritical:OSErr;
- INLINE $303C,$000C,$ABF2;
-
- FUNCTION SetDebuggerNotificationProcs ( notifyNewThread: DebuggerNewThreadProcPtr;
- notifyDisposeThread: DebuggerDisposeThreadProcPtr;
- notifyThreadScheduler: DebuggerThreadSchedulerProcPtr ):OSErr;
- INLINE $303C,$060D,$ABF2;
-
- FUNCTION GetThreadCurrentTaskRef ( VAR threadTRef: ThreadTaskRef ):OSErr;
- INLINE $303C,$020E,$ABF2;
-
- FUNCTION GetThreadStateGivenTaskRef ( threadTRef: ThreadTaskRef; threadToGet: ThreadID; VAR threadState: ThreadState ):OSErr;
- INLINE $303C,$060F,$ABF2;
-
- FUNCTION SetThreadReadyGivenTaskRef ( threadTRef: ThreadTaskRef; threadToSet: ThreadID ):OSErr;
- INLINE $303C,$0410,$ABF2;
-
- {$IFC NOT UsingIncludes}
- END.
- {$ENDC}
-